package com.itheima.springbootwebtlias.service.impl;


import com.itheima.springbootwebtlias.mapper.EmpMapper;
import com.itheima.springbootwebtlias.mapper.StudentMapper;
import com.itheima.springbootwebtlias.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    // 员工职位人数统计
    @Override
    public Map jobCount() {
        // 1.调用持久层EmpMapper的方法，查询员工职位人数统计
        List<Map> jobList = empMapper.jobCount();

        // 2.处理查询结果
        Map map = new HashMap();
        map.put("jobList", jobList.stream().map(item -> item.get("name")).collect(Collectors.toList()));
        map.put("dataList",jobList.stream().map(item -> item.get("value")).collect(Collectors.toList()));

        // 3.封装响应结果
        return map;
    }

    // 员工性别统计

    @Override
    public List<Map> genderCount() {
        // 1.调用持久层EmpMapper的方法，查询员工性别人数统计
        return empMapper.genderCount();
    }

    // 学生班级统计
    @Override
    public Map getClazzCountData() {
        // 1.调用持久层EmpMapper的方法，查询员工职位人数统计
        List<Map> clazzList = studentMapper.countClassData();

        // 2.处理查询结果
        Map map = new HashMap();
        map.put("clazzList", clazzList.stream().map(item -> item.get("name")).collect(Collectors.toList()));
        map.put("dataList",clazzList.stream().map(item -> item.get("total")).collect(Collectors.toList()));

        // 3.封装响应结果
        return map;
    }

    // 学生学历统计
    @Override
    public List<Map> getStudenDegreeData() {
        return studentMapper.countStudentDegreeData();
    }
}
